package com.hongling.uc.ons.producer;

import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.Producer;
import com.aliyun.openservices.ons.api.SendResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;

/**
 * 调用生产者测试。
 * 查看打印日志，打印了发送上去的messageId。就证明数据已经生产并发送成功了。
 */
public class TestSendMessage {
    private final static Logger logger = LoggerFactory.getLogger(TestSendMessage.class);
    @Value("${ons.topic.transaction}")
    private static String TOPIC;
    public static void main(String[] args) {
 
        StringBuilder logsb=new StringBuilder("send OnsMQ Msg:");
        Producer producer = CloudMQUtil.getProducer(); //你申请的producerId
        Message msg = new Message("UC-Transaction-Dev", //你申请的TopicName
                "*","这是消息2".getBytes());
        SendResult sendResult = producer.send(msg);
        String messageId = "";
        messageId = sendResult.getMessageId();
        if (messageId != null || !messageId.equals("")) {
            logsb.append("[OnsProducer] : " + "{ messageId : " + messageId + " , msgStr :" + "这是消息2" + "}");
        } else {
            logsb.append("[OnsProducer] fail: " + "{ " + " msgStr :" + "这是消息2" + "}");
        }
        logger.debug(logsb.toString());
    }
}